package com.weixin.pay;

import com.weixin.pay.business.*;
import com.weixin.pay.domain.close.CloseOrderReqData;
import com.weixin.pay.domain.close.CloseOrderResData;
import com.weixin.pay.domain.micropay.MicroPayReqData;
import com.weixin.pay.domain.micropay.MicroPayResData;
import com.weixin.pay.domain.prepay.PrePayReqData;
import com.weixin.pay.domain.prepay.PrePayResData;
import com.weixin.pay.domain.query.OrderQueryReqData;
import com.weixin.pay.domain.query.OrderQueryResData;
import com.weixin.pay.domain.query.RefundQueryReqData;
import com.weixin.pay.domain.query.RefundQueryResData;
import com.weixin.pay.domain.refund.RefundReqData;
import com.weixin.pay.domain.refund.RefundResData;
import com.weixin.pay.domain.reverse.ReverseReqData;
import com.weixin.pay.domain.reverse.ReverseResData;
import com.weixin.pay.http.HttpClientHolder;

/**
 * 微信支付默认客户端实现
 */
public class DefaultWeiXinPayClient implements WeiXinPayClient {

    /**
     * 微信支付配置信息
     */
    private WeiXinPayConfigure configure;

    /**
     * 微信支付请求持有类
     */
    private HttpClientHolder httpClientHolder;

    /**
     * 构造方法，需要传入微信支付配置信息
     *
     * @param configure 微信支付配置信息
     */
    public DefaultWeiXinPayClient(WeiXinPayConfigure configure) {
        this.configure = configure;
        this.httpClientHolder = new HttpClientHolder(configure.getCertLocalPath(), configure.getCertPassword());
    }

    public WeiXinResult<PrePayResData> prePay(PrePayReqData prePayReqData) {
        return new PrePayBusiness(httpClientHolder, configure).prePay(prePayReqData);
    }

    public WeiXinResult<OrderQueryResData> orderQuery(OrderQueryReqData orderQueryReqData) {
        return new OrderQueryBusinss(httpClientHolder, configure).orderQuery(orderQueryReqData);
    }

    public WeiXinResult<CloseOrderResData> closeOrder(CloseOrderReqData closeOrderReqData) {
        return new CloseOrderBusiness(httpClientHolder, configure).closeOrder(closeOrderReqData);
    }

    public WeiXinResult<RefundResData> refund(RefundReqData refundReqData) {
        return new RefundBusiness(httpClientHolder, configure).refund(refundReqData);
    }

    public WeiXinResult<RefundQueryResData> refundQuery(RefundQueryReqData refundQueryReqData) {
        return new RefundQueryBusiness(httpClientHolder, configure).refundQuery(refundQueryReqData);
    }

    public WeiXinResult<MicroPayResData> microPay(MicroPayReqData microPayReqData) {
        return new MicroPayBusiness(httpClientHolder, configure).microPay(microPayReqData);
    }

    public WeiXinResult<MicroPayResData> microPaySimple(MicroPayReqData microPayReqData) {
        return new MicroPayBusinessSimple(httpClientHolder, configure).microPay(microPayReqData);
    }

    public WeiXinResult<ReverseResData> reverse(ReverseReqData reverseReqData) {
        return new ReverseBusiness(httpClientHolder, configure).reverse(reverseReqData);
    }

    public WeiXinPayConfigure getConfigure() {
        return configure;
    }
}
